package net.gpai.tool

import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import gtool.composeapp.generated.resources.Res
import gtool.composeapp.generated.resources.gpai_icon
import org.jetbrains.compose.resources.painterResource
import java.awt.Dimension

fun main() = application {
    val state = rememberWindowState(
        size = DpSize(900.dp, 800.dp)   // 初始大小
    )
    var showConfirmDialog by remember { mutableStateOf(false) }

    Window(
        onCloseRequest = {
            showConfirmDialog = true
        },
        title = "gtool",
        state = state,
        icon = painterResource(Res.drawable.gpai_icon),
    ) {
        // 关键：窗口创建完成后设置最小/最大尺寸
        LaunchedEffect(Unit) {
            window.minimumSize = Dimension(600, 400)
            window.maximumSize = Dimension(900, 600)
        }
        val colorScheme = lightColorScheme(
            primary = Color(0xFF2ecc71),
            onPrimary = Color.White,
            /* 其余按需覆盖 */
        )

        MaterialTheme(colorScheme = colorScheme) {
            if (showConfirmDialog) {
                AlertDialog(
                    onDismissRequest = { showConfirmDialog = false },
                    confirmButton = {
                        Button(
                            onClick = { exitApplication() }   // 关键点：放在 onClick 里
                        ) {
                            Text("确定")
                        }
                    },
                    dismissButton = {
                        TextButton(
                            onClick = { showConfirmDialog = false }
                        ) {
                            Text("取消")
                        }
                    },
                    title = { Text("提示") },
                    text = {
                        Text("确定要退出应用吗")
                    }
                )
            }
            Index()
        }
    }
}